package com.atguigu.gmall.product.controller;

/**
 * ClassName: BaseTrademarkController
 * Package: com.atguigu.gmall.product.controller
 * Description:
 *
 * @Author 刘轩
 * @Create 2023-08-18 20:56
 * @Version 1.0
 */

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 品牌表 前端控制器
 */
@Api(tags = "品牌表控制器")
@RestController
@RequestMapping("/admin/product/baseTrademark")

public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    /**
     * 品牌分页查询
     *
     * @param page
     * @param limit
     * @return
     */
    @ApiOperation(value = "品牌分页查询")
    @GetMapping("/{page}/{limit}")
    public Result getTradeMarkList(@PathVariable Long page,
                                   @PathVariable Long limit) {
        // Select * from base_trademark order by id desc limit 2,2;
        Page<BaseTrademark> baseTrademarkPage = new Page<>(page, limit);
        IPage<BaseTrademark> iPage = baseTrademarkService.getTradeMarkList(baseTrademarkPage);
        return Result.ok(iPage);
    }

    /**
     * 保存品牌
     *
     * @return
     */
    @PostMapping("/save")
    public Result sava(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    /**
     * 删除品牌
     * @param id
     * @return
     */
    @DeleteMapping("/remove/{id}")
    public Result removeById(@PathVariable Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    /**
     * 根据id获取品牌
     * @param id
     * @return
     */

    @GetMapping("/get/{id}")
    public Result getById(@PathVariable Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }
    @PutMapping("/update")
    public Result updateTradeMarkById(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }
}
